package gwtgaetools.client.ui;

import gwtgaetools.client.listeners.DeleteListener;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Composite;

// TODO: register delete listener here.
public abstract class BasicLabel<M> extends Composite implements DeleteListener<M>  {

	protected boolean selected = false;
	
	public M item;

	// The panel to which this label is added.
	RemoveListener<BasicLabel<M>> deleteListener;
	
	public BasicLabel(M t) {
		item = t;
	}
	
	public void setDeleteListener(RemoveListener<BasicLabel<M>> dl) {
		deleteListener = dl;
	}

	public HandlerRegistration addClickHandler(ClickHandler ch) {
		return addDomHandler(ch, ClickEvent.getType());
	}

	@Override
	public void delete(M t) {
		if (deleteListener!=null)
			deleteListener.remove(this);
	}

	public void setSelected(boolean b) {}

	public boolean isSelected() {
		return selected;
	}

}
